/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package stock.utils;

import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

/**
 * 创建一个可写的 Excel 文件
 * @author peter
 */
public class WExcelFile {
    private WritableWorkbook wwb = null;
    private WritableSheet sheet = null;

    public WExcelFile(File file) throws Exception {
        wwb = Workbook.createWorkbook(file);
        sheet = wwb.createSheet("First Sheet", 0);
    }
    
    public void createSheet(String name, int i) {
        sheet = wwb.createSheet(name, i);
    }
    /**
     * 
     * @param row 行
     * @param col 列
     * @param value 值
     */
    public void addCell(int row, int col, String value) 
            throws WriteException {
        Label label = new Label(col, row, value);
        sheet.addCell(label);
    }

    public void write() throws IOException {
        wwb.write();
    }

    public void close() throws Exception {
        wwb.close();
    }
}
